﻿using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.ReadApi.Command.Raddit.BW;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander.Raddit.BWHA
{
    public class GetSupplierCommandHander : IRequestHandler<GetSupplierCommand, ApiResult<Supplier>>
    {
        public readonly IRepistory<Supplier> _supplierRepistory;
        public GetSupplierCommandHander(IRepistory<Supplier> supplierRepistory)
        {
            _supplierRepistory = supplierRepistory;
        }
        /// <summary>
        /// 获取供应商信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<Supplier>> Handle(GetSupplierCommand request, CancellationToken cancellationToken)
        {
            ApiResult<Supplier> apiResult = new ApiResult<Supplier>();
            var result=_supplierRepistory.GetAll().FirstOrDefault(x=>x.BatchId==request.BatchId);
            apiResult.Data = result;
            apiResult.Message =Renum.显示成功.ToString();
            apiResult.code = Renum.显示成功;
            return Task.FromResult(apiResult);

        }
    }
}
